/*
 * Urgência.java
 *
 * Created on 26 de Janeiro de 2009, 19:22
 */

package cadastros;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import utilitarios.conexao;

/**
 *
 * @author  Shinigami
 */
public class urgencia extends javax.swing.JFrame {

    /** Creates new form Urgência */
    conexao con_server, con_servf, con_aberto, con_pesq, con_atual, con_ordem;
    int ordem, ord;
    
    public urgencia() {
        initComponents();
    
    con_atual = new conexao();
    con_atual.conecta();
    
    con_ordem = new conexao();
    con_ordem.conecta();
    
    lb_codcall.setVisible(false);
    
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cb_urg = new javax.swing.JComboBox();
        bt_urg = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        lb_codcall = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Urgência");
        setResizable(false);

        jLabel1.setText("Selecione a urgência do chamado:");

        cb_urg.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ALTA", "MÉDIA", "BAIXA" }));

        bt_urg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/dialog-apply.png"))); // NOI18N
        bt_urg.setToolTipText("OK");
        bt_urg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_urgActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cb_urg, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(bt_urg, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lb_codcall, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_urg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bt_urg, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(lb_codcall, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-205)/2, (screenSize.height-171)/2, 205, 171);
    }// </editor-fold>//GEN-END:initComponents

private void bt_urgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_urgActionPerformed

    try
    {
            
                    
            int codurg = 0;
            
            if(cb_urg.getSelectedItem().equals("ALTA"))
            {
                codurg = 1;
            }
            else if(cb_urg.getSelectedItem().equals("MÉDIA"))
            {
                codurg = 2;
            }
            else if(cb_urg.getSelectedItem().equals("BAIXA"))
            {
                codurg = 3;
            }
            
            String codcall = hd_server.lb_ncall.getText();
            
            String sql = "UPDATE helpdeska SET status ='EM ANDAMENTO',tecnicoa = '"+hd_principal.lb_tec.getText()+"',urgenciaa ='"+cb_urg.getSelectedItem()+"',codurgencia ='"+codurg+"',tecnico = '"+hd_principal.lb_tec.getText()+"',horarioa = '"+hd_server.lb_horaab.getText()+"'Where codcalla ="+codcall;
            con_atual.executasql("select * from helpdeska where codcalla="+codcall); 
            con_atual.resultset.first();
            con_atual.statement.executeUpdate(sql);
            
            
            
            con_ordem.executasql("select * from helpdeska where status like 'EM ANDAMENTO' and codurgencia ='"+codurg+"'order by ordem");
            
            if(con_ordem.resultset != null)
            {
                
            con_ordem.resultset.last();
            
            ord = con_ordem.resultset.getInt("ordem");
            ordem = ord + 1;   
             
            
            }
            else if(con_ordem.resultset == null)
            {
                ord = 0;
                ordem = ord +1;
            }
                        
        
   
            String qsql = "UPDATE helpdeska SET ordem ='"+ordem+"'Where codcalla ="+codcall;
            con_atual.executasql("select * from helpdeska where codcalla="+codcall); 
            con_atual.resultset.first();
            con_atual.statement.executeUpdate(qsql);    
            
            
            //hd_principal.con_hdserver.executasql("select * from helpdeska where codcalla="+codcall);
            hd_principal.con_hdserver.executasql("select * from helpdeska");
            hd_principal.con_hdserver.resultset.beforeFirst();
            //new hd_server().setVisible(true);
            while(hd_principal.con_hdserver.resultset.next())
            {
                if(hd_principal.con_hdserver.resultset.getString("codcalla").equals(codcall))
                {
                 hd_server.mostrar_dados();
                 break;
                }
                else
                {
                    continue;
                }
            }
            
            
            
            /*hd_server.lb_status.setText(con_aberto.resultset.getString("status"));
            hd_server.lb_tecresp.setText(con_aberto.resultset.getString("tecnicoa"));
            hd_server.lb_urg.setText(con_aberto.resultset.getString("urgenciaa"));*/
            
           
    
    }
    catch (SQLException ex) {
            Logger.getLogger(hd_principal.class.getName()).log(Level.SEVERE, null, ex);
        }
    
    setVisible(false);
}//GEN-LAST:event_bt_urgActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new urgencia().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_urg;
    private javax.swing.JComboBox cb_urg;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    public static javax.swing.JLabel lb_codcall;
    // End of variables declaration//GEN-END:variables

}
